package com.qyhl.module_activities.act.live;


import com.qyhl.module_activities.app.ActivitiesApplication;
import com.qyhl.module_activities.common.ActUrl;
import com.qyhl.webtv.basiclib.utils.NetUtil;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.act.TeleVoteBean;

public class TeleVoteModel implements TeleVoteContract.TeleVoteModel {
    private TeleVoteContract.TeleVotePresenter presenter;

    public TeleVoteModel(TeleVoteContract.TeleVotePresenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void getData(String actId, String linkId, String userName) {
        if (NetUtil.isNetworkAvalible(ActivitiesApplication.getApp())) {

            EasyHttp.get(ActUrl.GET_TELETEXT_VOTE_LIST)
                    .params("sActId", actId)
                    .params("linkId", linkId)
                    .params("linkType", "0")
                    .params("voter", userName)
                    .execute(new SimpleCallBack<TeleVoteBean>() {
                        @Override
                        public void onError(ApiException e) {
                            presenter.setError("获取失败!");
                        }

                        @Override
                        public void onSuccess(TeleVoteBean teleVoteBean) {
                            presenter.setDetail(teleVoteBean);
                        }
                    });
        } else {
            presenter.setError("请检查网络...");
        }
    }
}
